package eight_RemoveElement;

public class CSolution {

    public static void main(String[] args) {
//        System.out.println("aa");
        System.out.println(removeElement(new int[]{0, 1, 2, 2, 3, 0, 4, 2}, 2));
//        System.out.println(removeElementTest(new int[]{0, 1, 2, 2, 3, 0, 4, 2}, 2));
//        System.out.println(removeElement(new int[]{0, 1, 2, 2, 3, 0, 4, 2}, 2));
    }

    //TODO double pointer!

    private static int removeElement(int[] nums, int val) {
        if (nums == null || nums.length == 0) {
            return 0;
        }
        int i = 0;
        int j = 0;
        while (j<nums.length) {
            if(nums[j]!=val) {
                nums[i++] = nums[j];
            }
            j++;
        }
        return i;
    }
}
